var debug = process.env.NODE_ENV !== 'production';
var path = require('path'); 
var htmlWebpackPlugin = require('html-webpack-plugin');
var webpack = require('webpack');

var plugins = [
		new webpack.optimize.CommonsChunkPlugin({
			name: ['react', 'vendor'],
			minChunks: Infinity
		}),
		new webpack.ProvidePlugin({
			$: 'jquery'
		}),
		new htmlWebpackPlugin({
			filename: '../index.html',
			template: 'src/index.html',
			inject: true,
			chunks: ['react', 'vendor', 'app']
		})
	];
if(!debug) 
	plugins.push(
		new webpack.optimize.UglifyJsPlugin({
			compress: {warnings: false}
		}));


module.exports = {
	devtool: debug ? 'eval-source-map' : null,
	entry: {
		app: './src/js/app.js',
		react: ['react', 'react-dom'],
		vendor: ['jquery']
	},
	output: {
		path: './dist/js',
		filename: debug ? '[name].js' : '[name]-[hash:8].js'
	},
	module: {
		loaders: [
			{
				test: /\.jsx?/, 
				exclude: /node_modules/,
				loader: 'babel-loader',
				query: {
					presets: ['react', 'es2015']
				}
			}
		]
	},
	plugins: plugins
};